// pages/past_scores_comparison/past_scores_comparison.js
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },

    goToQueryRecordPage: function () {
        // 跳转到查询记录页面
        wx.navigateTo({
            url: '/pages/query_record/query_record',
        })
    },

    // 获取输入的信息
    inputSchoolName: function (e) {
        this.setData({
            schoolName: e.detail.value
        })
    },
    inputDepartment: function (e) {
        this.setData({
            department: e.detail.value
        })
    },
    inputMajorName: function (e) {
        this.setData({
            majorName: e.detail.value
        })
    },
    inputPoliticalScore: function (e) {
        this.setData({
            politicalScore: e.detail.value
        })
    },
    inputForeignLanguageScore: function (e) {
        this.setData({
            foreignLanguageScore: e.detail.value
        })
    },
    inputMajorCourseOneScore: function (e) {
        this.setData({
            majorCourseOneScore: e.detail.value
        })
    },
    inputMajorCourseTwoScore: function (e) {
        this.setData({
            majorCourseTwoScore: e.detail.value
        })
    },

    // 点击开始分析按钮的事件处理函数
    startAnalysis: function () {
        // 检查是否所有信息都已填写
        if (!this.data.schoolName || !this.data.department || !this.data.majorName || !this.data.politicalScore || !this.data.foreignLanguageScore || !this.data.majorCourseOneScore || !this.data.majorCourseTwoScore) {
            wx.showToast({
                title: '请填写完整信息',
                icon: 'none'
            })
            return;
        }

        // 检查政治分数、外语分数、专业课一分数、专业课二分数是否为数字
        if (isNaN(this.data.politicalScore) || isNaN(this.data.foreignLanguageScore) || isNaN(this.data.majorCourseOneScore) || isNaN(this.data.majorCourseTwoScore)) {
            wx.showToast({
                title: '分数必须为数字',
                icon: 'none'
            })
            return;
        }
        //   // 获取输入的信息
        //   const schoolName = this.data.schoolName;
        //   const department = this.data.department;
        //   const majorName = this.data.majorName;
        console.log(789789)
        const pastscore = {
            schoolName: this.data.schoolName,
            department: this.data.department,
            majorName: this.data.majorName,
            politicalAvg: this.data.politicalScore,
            foreignLanguageAvg: this.data.foreignLanguageScore,
            majorCourseOneAvg: this.data.majorCourseOneScore,
            majorCourseTwoAvg: this.data.majorCourseTwoScore
        }
        console.log(pastscore);
        // 向后端发送请求
        wx.request({
            url: 'http://localhost:8080/springboot0ti08m1q/getscorebyname3',
            method: 'POST',
            data: pastscore, // 要发送的数据，这里假设为一个对象
            header: {
                'content-type': 'application/json' // 告诉后端发送的数据是 JSON 格式
            },
            success(res) {
                console.log(res.data) // 打印后端返回的数据
                // 在这里进行页面跳转，并传递后端返回的数据到分析结果界面
                const da=JSON.stringify(res.data);
                console.log(da);
                console.log(pastscore)
                wx.navigateTo({
                    url: '/pages/analysis_result/analysis_result?da=' + encodeURIComponent(JSON.stringify(da)) + '&pastscore=' + encodeURIComponent(JSON.stringify(pastscore))
                });

            },
            fail(err) {
                console.error(err) // 打印请求失败的错误信息
            }
        });

        // 执行分析操作
        console.log("开始分析");
        console.log("院校名称:", this.data.schoolName);
        console.log("二级学院:", this.data.department);
        console.log("专业名称:", this.data.majorName);
        console.log("政治分数:", this.data.politicalScore);
        console.log("外语分数:", this.data.foreignLanguageScore);
        console.log("专业课一分数:", this.data.majorCourseOneScore);
        console.log("专业课二分数:", this.data.majorCourseTwoScore);
    },

    // 页面数据
    data: {
        schoolName: '',
        department: '',
        majorName: '',
        politicalScore: '',
        foreignLanguageScore: '',
        majorCourseOneScore: '',
        majorCourseTwoScore: ''
    }




})